import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import 'element-plus/dist/index.css'
import './styles/index.css'

import App from './App.vue'
import router from './router'
import { useAuthStore } from './store/auth'
import { useSidebarStore } from './store/sidebar'
import { chartResize } from './directives/resize'

// 添加被动事件监听器，提高滚动性能
import 'default-passive-events'

// 创建应用实例
const app = createApp(App)

// 注册所有Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 注册自定义指令
app.directive('chart-resize', chartResize)

// 1. 先初始化Pinia
const pinia = createPinia()
app.use(pinia)

// 初始化认证状态
const authStore = useAuthStore()
authStore.initFromStorage()

// 初始化侧边栏状态
const sidebarStore = useSidebarStore()
sidebarStore.initFromStorage()

// 2. 再初始化路由
app.use(router)

// 3. 最后挂载应用
app.use(ElementPlus)
app.mount('#app') 